Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema:[],
    formData:{
      redDotIndex: 0,
      animation: false,
      color: '#FF0000',
      selectedColor: '#00FF00',
      backgroundColor: '#0000FF',
      borderStyle: 'white',
      index: 0,
      text: 'text',
      iconPath: '/path/to/iconPath',
      selectedIconPath: '/path/to/selectedIconPath',
      setBadgeIndex: 0,
      setBadgeText: '1',
      removeBadgeIndex: 0,
      hideTabBarRedDotIndex: 0
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    apiName: '',
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })
    
    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
    if(options.zh === 'wx.showTabBarRedDot') {
      this.setData({
        schema: [
          {
            label:'tabBar 的哪一项，从左边算起',
            prop:'redDotIndex',
            type:'number'
          }
        ]
      })
    }
    if(options.zh === 'wx.showTabBar') {
      this.setData({
        schema: [
          {
            label:'是否需要动画效果',
            prop:'animation',
            type:'switch'
          }
        ]
      })
    }
    if(options.zh === 'wx.setTabBarStyle') {
      this.setData({
        schema: [
          {
            label:'tab 上的文字默认颜色，HexColor',
            prop:'color',
            type:'text'
          },
          {
            label:'tab 上的文字选中时的颜色，HexColor',
            prop:'selectedColor',
            type:'text'
          },
          {
            label:'tab 的背景色，HexColor',
            prop:'backgroundColor',
            type:'text'
          },
          {
            label:'tabBar上边框的颜色， 仅支持 black/white',
            prop:'borderStyle',
            type:'picker',
            labelOptions:['black','white'],
            valueOptions:['black', 'white'],
          }
        ]
      })
    }
    if(options.zh === 'wx.setTabBarItem') {
      this.setData({
        schema: [
          {
            label:'tabBar 的哪一项，从左边算起',
            prop:'index',
            type:'number'
          },
          {
            label:'tab 上的按钮文字',
            prop:'text',
            type:'text'
          },
          {
            label:'图片路径，icon 大小限制为 40kb，建议尺寸为 81px * 81px，当 postion 为 top 时，此参数无效',
            prop:'iconPath',
            type:'text'
          },
          {
            label:'选中时的图片路径，icon 大小限制为 40kb，建议尺寸为 81px * 81px ，当 postion 为 top 时，此参数无效',
            prop:'selectedIconPath',
            type:'text'
          }
        ]
      })
    }
    if(options.zh === 'wx.setTabBarBadge') {
      this.setData({
        schema: [
          {
            label:'tabBar 的哪一项，从左边算起',
            prop:'setBadgeIndex',
            type:'number'
          },
          {
            label:'显示的文本，超过 4 个字符则显示成 ...',
            prop:'setBadgeText',
            type:'text'
          }
        ]
      })
    }
    if(options.zh === 'wx.removeTabBarBadge') {
      this.setData({
        schema: [
          {
            label:'tabBar 的哪一项，从左边算起',
            prop:'removeBadgeIndex',
            type:'number'
          }
        ]
      })
    }
    if(options.zh === 'wx.hideTabBarRedDot') {
      this.setData({
        schema: [
          {
            label:'tabBar 的哪一项，从左边算起',
            prop:'hideTabBarRedDotIndex',
            type:'number'
          }
        ]
      })
    }
  },
  getFormData(e) {
    console.log('e.detail.formData', e.detail.formData);
    this.setData({
      formData: e.detail.formData
    })
  },
  showTabBarRedDot(e) {
    const that = this;
    wx.showTabBarRedDot({
      index: this.data.formData.redDotIndex,
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
  showTabBar(e) {
    const that = this;
    wx.showTabBar({
      animation: this.data.formData.animation,
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
  setTabBarStyle(e) {
    const that = this;
    wx.setTabBarStyle({
      color: this.data.formData.color,
      selectedColor: this.data.formData.selectedColor,
      backgroundColor: this.data.formData.backgroundColor,
      backgroundColor: this.data.formData.backgroundColor,
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
  setTabBarItem(e) {
    const that = this;
    wx.setTabBarItem({
      index: this.data.formData.index,
      text: this.data.formData.text,
      iconPath: this.data.formData.iconPath,
      selectedIconPath: this.data.formData.selectedIconPath,
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
  setTabBarBadge(e) {
    const that = this;
    wx.setTabBarBadge({
      index: this.data.formData.setBadgeIndex,
      text: this.data.formData.setBadgeText,
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
  removePageSetTabBarBadge() {
    wx.setTabBarBadge({
      index: this.data.formData.removeBadgeIndex,
      text: '测试移除'
    })
  },
  removeTabBarBadge(e) {
    const that = this;
    wx.removeTabBarBadge({
      index: this.data.formData.removeBadgeIndex,
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
  hidePageShowTabBarRedDot() {
    const that = this;
    wx.showTabBarRedDot({
      index: this.data.formData.hideTabBarRedDotIndex
    })
  },
  hideTabBarRedDot(e) {
    const that = this;
    wx.hideTabBarRedDot({
      index: this.data.formData.hideTabBarRedDotIndex,
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
  hideTabBar(e) {
    const that = this;
    wx.hideTabBar({
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  }
})